import pytest
import logging

from fixture.fixture import api
from utils.read import *



class Test_case:
    headers = None
    id = None
    def test_01_login(self,api):
        logging.info("开始登录")
        data = {"phone": "13811033965", "pwd": "123456Aa"}
        req = api.post(url='/small/user/v1/login',status="json",data=data)
        assert req.status_code == 200
        assert req.json()["message"] == '登录成功'
        Test_case.headers = {"userId": str(req.json()['result']['userId']), "sessionId": req.json()['result']['sessionId']}
        logging.info("登录结束")

    @pytest.mark.parametrize('data',read_json(r'C:\Users\34098\PycharmProjects\yue11.10\data\add.json'))
    def test_01_add_address(self, api,data):
        logging.info("开始添加")
        data = {"realName":data['realName'],"phone":data['phone'],"address":data['address'],"zipCode":data['zipCode']}
        req = api.post(url='/small/user/verify/v1/addReceiveAddress',status='data',data=data,headers=Test_case.headers)
        print(req.json())
        logging.info("结束添加")

    def test_02_get_address(self,api):
        logging.info("开始查询")
        req = api.get(url='/small/user/verify/v1/receiveAddressList',headers=Test_case.headers)
        Test_case.id = req.json()['result'][0]['id']
        print(req.json()['message'])
        logging.info("结合查询")

    @pytest.mark.parametrize('data', read_yaml(r'C:\Users\34098\PycharmProjects\yue11.10\data\put.yaml'))
    def test_03_put_address(self, api,data):
        logging.info("开始修改")
        data = {"id":Test_case.id,"realName":data['realName'],"phone":data['phone'],"address":data['address'],"zipCode":data['zipCode']}
        req = api.put(url='/small/user/verify/v1/changeReceiveAddress',status='data',data=data,headers=Test_case.headers)
        print(req.json())
        logging.info("修改结束")

    def test_04_delete_address(self,api):
        logging.info("开始删除")
        data = {"id":Test_case.id}
        req = api.delete(url='/small/user/verify/v1/deleteReceiveAddress',status='data',data=data,headers=Test_case.headers)
        print(req.json())
        logging.info("成功删除")



